<?php

$headings = ( $this->lang == 'en' ) 
	? array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')
	: array('星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');

// Previous and next month timestamps
$next = mktime(0, 0, 0, $month + 1, 1, $year);
$prev = mktime(0, 0, 0, $month - 1, 1, $year);

// Import the GET query array locally and remove the day
$qs = $_GET;
unset($qs['day']);

// Previous and next month query URIs
//$prev = Router::$current_uri.'?'.http_build_query(array_merge($qs, array('month' => date('n', $prev), 'year' => date('Y', $prev))));
//$next = Router::$current_uri.'?'.http_build_query(array_merge($qs, array('month' => date('n', $next), 'year' => date('Y', $next))));

$prev = 'calender/index/'.date('n', $prev).'/'.date('Y', $prev);
$next = 'calender/index/'.date('n', $next).'/'.date('Y', $next);

?>
<?=html::script('js/overlib_mini.js')?>
<table class="h-calendar">
<caption class="controls">
	<span class="prev"><?php echo html::anchor($prev, '&laquo; Prev') ?></span>
	<span class="title" colspan="5"><?php echo strftime('%Y-%m', mktime(0, 0, 0, $month, 1, $year)) ?></span>
	<span class="next"><?php echo html::anchor($next, 'Next &raquo;') ?></span>
</caption>
<tr>
<?php foreach ($headings as $day) { ?>
	<th><?php echo $day ?></th>
<?php } ?>
</tr>
<?php 
	foreach ($weeks as $week) 
	{ 
		if(count($week)>0)
		{
?>
<tr>
<?php 
			foreach ($week as $day) 
			{
				list ($number, $current, $data) = $day;
				
				if (is_array($data))
				{
					$classes = $data['classes'];
					$output = empty($data['output']) ? '' : '<ul class="output"><li>'.implode('</li><li>', $data['output']).'</li></ul>';
				}
				else
				{
					$classes = array();
					$output = '';
				}
?>
	<td class="<?php echo implode(' ', $classes) ?>"><div class="day"><?php echo $day[0] ?></div><?php echo $output ?></td>
	<?php } } ?>
</tr>
<?php } ?>
</table>
<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>

